﻿using COMOSOFT.JobManagement.USC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace COMOSOFT.HumanResource.Forms
{
    public partial class FrmEmployeeList : Form
    {
        FrmPreview frmPV = null;
        UscStaffInfo uscStaffInfo = null;
        public FrmEmployeeList()
        {
            InitializeComponent();
        }

        #region[LoadData]
        public void LoadData()
        {            
            uscStaffInfo = new UscStaffInfo();
            groupControl_EmpoyeeDetail.Controls.Add(uscStaffInfo);
            uscStaffInfo.Dock = DockStyle.Fill;
            employeeTableAdapter.Fill(this.dataSet_HumanResource.Employee);
            uscStaffInfo.LoadList();
            uscStaffInfo.Show();
            
        }
        public void RefreshData()
        {
            employeeTableAdapter.Fill(this.dataSet_HumanResource.Employee);
            uscStaffInfo.LoadList();
        }
        #endregion

        private void gridView_EmployeeList_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            try
            {
                employeeBindingSource.EndEdit();
                employeeTableAdapter.Update(dataSet_HumanResource.Employee);
                dataSet_HumanResource.Employee.AcceptChanges();
                LoadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void PreView()
        {
            frmPV = new FrmPreview(gridView_EmployeeList);
            frmPV.LoadData();
            frmPV.Show();
        }

        private void gridView_EmployeeList_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (uscStaffInfo != null || !uscStaffInfo.IsDisposed)
            {
                uscStaffInfo.SelectItem(e.FocusedRowHandle);
            }
        }
    }
}
